//
//  NSObject+Extension.swift
//  QingLiuSwift
//
//  Created by xyanl on 2023/8/21.
//

import Foundation
import UIKit

extension NSObject {
    
    func objc_setAssociated<T>(_ key: inout T, _ value: Any, _ policy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC) -> Void {
        let associatedKey = withUnsafePointer(to: key) { $0 }
        objc_setAssociatedObject(self, associatedKey, value, policy)
    }
    
    func objc_getAssociated<T>(_ key: inout T) -> Any? {
        let associatedKey = withUnsafePointer(to: key) { $0 }
        return objc_getAssociatedObject(self, associatedKey)
    }
}
